package com.eleMall.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * Swagger配置
 *
 * @author makejava
 * @since 2024-03-11 15:43:12
 */
@Slf4j
@Configuration
@EnableOpenApi

public class SwaggerConfig {
    /**
     * 用于读取配置文件 swagger 属性是否开启
     */

    Boolean swaggerEnabled = true;

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                // 是否开启swagger
                .enable(swaggerEnabled)
                .select()
                // 过滤条件，扫描指定路径下的文件
                .apis(RequestHandlerSelectors.basePackage("com.eleMall.controller"))
                // 指定路径处理，PathSelectors.any()代表不过滤任何路径
                //.paths(PathSelectors.none())
                .build();
    }

    /**
     * 作者信息
     */
    private ApiInfo apiInfo() {
        Contact contact = new Contact
                ("Peter Cheung",
                        "https://github.com/PerCheung",
                        "13733139823@163.com");
        return new ApiInfo(
                "农技分享平台-商城服务",
                "农技分享平台-商城服务 测试接口文档",
                "v1.0",
                "https://github.com",
                contact,
                "Apache 2.0",
                "https://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>()
        );
    }
}

